﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AForge.Video.DirectShow;

namespace ueg
{
    public partial class CamSelector : Form
    {
        public FilterInfoCollection usbWebcams;
        public VideoCaptureDevice camSource;

        public CamSelector()
        {
            InitializeComponent();
            CamSelector_Load();
        }

        public void CamSelector_Load()
        {
            usbWebcams = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if (usbWebcams.Count == 0)
            {
                MessageBox.Show("No cameras were detected.");
                Close();
            }
            else
            {
                foreach (FilterInfo device in usbWebcams)
                {
                    comboBox1.Items.Add(device.Name);
                }
                comboBox1.SelectedIndex = 2;
            }
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            try
            {
                camSource = new VideoCaptureDevice(usbWebcams[comboBox1.SelectedIndex].MonikerString);
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("No selection was made.");
                CamSelector_Load();
            }
            finally
            {
                Close();
            }
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
